package com.ecarx.vhaltests.hy11.testcases.Utils;

import com.ecarx.vhaltests.IpcpClient;

import org.junit.Assert;

public class EcuUtil {

    public static class CEM{
        public static final int SERVICE_ID = 37;
        public static final int OPER_ID = 999;
    }

    public static class CDM{
        public static final int SERVICE_ID = 36;
        public static final int OPER_ID = 999;
    }

    public static class VDDM{
        public static final int SERVICE_ID = 48;
        public static final int OPER_ID = 999;
    }

    public static class BBM{
        public static final int SERVICE_ID = 33;
        public static final int OPER_ID = 999;
    }

    public static class DIM{
        public static final int SERVICE_ID = 0x0127;
    }

    public static class CarConfig{
        public static final int SERVICE_ID = 135;
        public static final int OPER_ID = 200;
    }

    public static class CarConfig1000{
        public static final int SERVICE_ID = 136;
        public static final int OPER_ID = 200;
    }

    public static class TimeOut {
        public static final int SERVICE_ID = 99;
        public static final int OPER_ID = 200;
    }

    public static void registerConfigCEM(IpcpClient ipcpClient) {
        int serviceId = CEM.SERVICE_ID;
        int[] operIds = {CEM.OPER_ID};
        boolean retCem = ipcpClient.setConfig(serviceId, operIds);
        Assert.assertTrue(retCem);
    }

    public static void registerConfigCDM(IpcpClient ipcpClient) {
        int serviceId = CDM.SERVICE_ID;
        int[] operIds = {CDM.OPER_ID};
        boolean retCem = ipcpClient.setConfig(serviceId, operIds);
        Assert.assertTrue(retCem);
    }

    public static void registerConfigVDDM(IpcpClient ipcpClient) {
        int serviceId = VDDM.SERVICE_ID;
        int[] operIds = {VDDM.OPER_ID};
        boolean retCem = ipcpClient.setConfig(serviceId, operIds);
        Assert.assertTrue(retCem);
    }

    public static void registerConfigBBM(IpcpClient ipcpClient) {
        int serviceId = BBM.SERVICE_ID;
        int[] operIds = {BBM.OPER_ID};
        boolean retCem = ipcpClient.setConfig(serviceId, operIds);
        Assert.assertTrue(retCem);
    }

    public static void registerConfigTimeout(IpcpClient ipcpClient) {
        int serviceId = TimeOut.SERVICE_ID;
        int[] operIds = {TimeOut.OPER_ID};
        boolean retCem = ipcpClient.setConfig(serviceId, operIds);
        Assert.assertTrue(retCem);
    }

    public static void registerConfigCarConfig(IpcpClient ipcpClient) {
        int serviceId = CarConfig.SERVICE_ID;
        int[] operIds = {CarConfig.OPER_ID};
        boolean retCem = ipcpClient.setConfig(serviceId, operIds);
        Assert.assertTrue(retCem);
    }

    public static void registerConfigDIM(IpcpClient ipcpClient, int[] operIds) {
        int serviceId = DIM.SERVICE_ID;
        boolean retCem = ipcpClient.setConfig(serviceId, operIds);
        Assert.assertTrue(retCem);
    }

    public static void registerConfigCarConfig1000(IpcpClient ipcpClient) {
        int serviceId = CarConfig1000.SERVICE_ID;
        int[] operIds = {CarConfig1000.OPER_ID};
        boolean retCem = ipcpClient.setConfig(serviceId, operIds);
        Assert.assertTrue(retCem);
    }

    public static void setCarConfig(IpcpClient ipcpClient, int[] requests, int[] values) {
        int serviceId = CarConfig.SERVICE_ID;
        int operId = CarConfig.OPER_ID;
        boolean ccResult = ipcpClient.setCarconfigSignal(serviceId, operId, requests, values);
        Assert.assertTrue(ccResult);
        delay();
    }

    public static void setCarConfig1000(IpcpClient ipcpClient, int[] requests, int[] values) {
        int serviceId = CarConfig1000.SERVICE_ID;
        int operId = CarConfig1000.OPER_ID;
        boolean ccResult = ipcpClient.setCarconfig1000Signal(serviceId, operId, requests, values);
        Assert.assertTrue(ccResult);
        delay();
    }

    public static void setTimeout(IpcpClient ipcpClient,String[] requests ,int[] values) {
        int serviceId = TimeOut.SERVICE_ID;
        int operId = TimeOut.OPER_ID;
        boolean result = ipcpClient.setTimeoutSignal(serviceId, operId, requests, values);
        Assert.assertTrue(result);
        delay();
    }

    public static void setVDDM(IpcpClient ipcpClient,String[] requests ,int[] values) {
        int serviceId = VDDM.SERVICE_ID;
        int operId = VDDM.OPER_ID;
        boolean result = ipcpClient.setVDDMSignal(serviceId, operId, requests, values);
        Assert.assertTrue(result);
        delay();
    }

    public static void setCDM(IpcpClient ipcpClient,String[] requests ,int[] values) {
        int serviceId = CDM.SERVICE_ID;
        int operId = CDM.OPER_ID;
        boolean result = ipcpClient.setCDMSignal(serviceId, operId, requests, values);
        Assert.assertTrue(result);
        delay();
    }

    public static void setCEM(IpcpClient ipcpClient,String[] requests ,int[] values) {
        int serviceId = CEM.SERVICE_ID;
        int operId = CEM.OPER_ID;
        boolean result = ipcpClient.setCEMSignal(serviceId, operId, requests, values);
        Assert.assertTrue(result);
        delay();
    }

    public static void setBBM(IpcpClient ipcpClient,String[] requests ,int[] values) {
        int serviceId = BBM.SERVICE_ID;
        int operId = BBM.OPER_ID;
        boolean result = ipcpClient.setBBMSignal(serviceId, operId, requests, values);
        Assert.assertTrue(result);
        delay();
    }

    public static void setDIM(IpcpClient ipcpClient,int operId, String[] requests ,int[] values) {
        int serviceId = DIM.SERVICE_ID;
//        int operId = DIM.OPER_ID;
        boolean result = ipcpClient.setDimHUDSignal(serviceId, operId, requests, values);
        Assert.assertTrue(result);
        delay();
    }

    public static void delay() {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
